#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 3;
ll c[maxn], a[maxn], b[maxn], f[maxn], maxc;
int n, m;
int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> c[i];
        maxc = max(maxc, c[i]);
    }
    for (int i = 1; i <= n; i++) {
        for (ll j = maxc; j >= a[i]; j--) {
            f[j] = max(f[j], f[j - a[i]] + b[i]);
        }
        cout << '\n';
    }
    for (int i = 1; i <= m; i++) 
        cout << f[c[i]] << '\n';
    
}